from os.path import join, dirname
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QMovie
from PyQt5.QtWidgets import QWidget, QApplication, QLabel

class MyWidget(QWidget):
    def __init__(self):
        super(MyWidget, self).__init__()
        self.setWindowTitle("使用QLabel显示gif图片示例")
        self.resize(800, 600)
        self.label = QLabel(self)
        self.label.setGeometry(0, 0, 300, 200)
        self.label.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.label.setAlignment(Qt.AlignCenter)
        gif_file = join(dirname(__file__), "res", "test.gif")
        movie = QMovie(gif_file)
        self.label.setMovie(movie)
        self.label.setScaledContents(True)
        movie.start()

app = QApplication([])
w = MyWidget()
w.show()
app.exec_()